﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sys.WebRes.Data
{
    public partial class AttachUrlType
    {
        public static Dictionary<int, AttachUrlType> Map = new Dictionary<int, AttachUrlType>();

        public static AttachUrlType DB       = new AttachUrlType(1, "数据库系统", "DB", "数据库系统", 1);
        public static AttachUrlType Path     = new AttachUrlType(2, "文件系统", "Path", "文件系统", 2 );
        public static AttachUrlType MaskPath = new AttachUrlType(3, "伪文件系统", "MaskPath", "伪文件系统", 3);
 



        public static void Initialize(ResourceSysEntities db)
        {
            var list = db.AttachUrlTypeTBL.ToList();
            if (list.Count > 0)
            {
                list.ForEach(p =>
                {
                    Map[p.ID].Name = p.Name;
                    Map[p.ID].Abbr = p.Abbr;
                    Map[p.ID].Explain = p.Explain;
                    Map[p.ID].OrderNo = p.OrderNo;
                });
            }
            else
            {
                Array.ForEach(Map.Values.ToArray(), p =>
                {
                    db.AddToAttachUrlTypeTBL(p);
                });
            }
        }

        private AttachUrlType(int id, string name, string abbr, string explain, int orderNo)
        {
            this.ID = id;
            this.Name = name;
            this.Abbr = abbr;
            this.Explain = explain;
            this.OrderNo = orderNo;

            Map.Add(id, this);
        }

        public AttachUrlType() { }
    }
}